﻿using System;
using System.Web.UI.WebControls;
using ContractManagementSystem.BusinessLogic;
using ContractManagementSystem.Entity;

namespace ContractManagementSystem
{
    public partial class PageReportContractor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ListContractorPanel.Visible = true;
                SearchContractor();
            }
        }

        public void SearchContractor()
        {
            if (!string.IsNullOrEmpty(FullNameTextBoxSearch.Text))
            {
                ViewAllContractListView.DataSource = ContractorBusiness.SearchFullName(FullNameTextBoxSearch.Text);
                ViewAllContractListView.DataBind();
                Session["ReportContractor"] = ContractorBusiness.SearchFullName(FullNameTextBoxSearch.Text);
            }
            else
            {
                ViewAllContractListView.DataSource = ContractorBusiness.FetchAll(ActiveDropDownList.SelectedIndex);
                ViewAllContractListView.DataBind();
                Session["ReportContractor"] = ContractorBusiness.FetchAll(ActiveDropDownList.SelectedIndex);
            }
        }

        protected void FullNameTextBoxTextChanged(object sender, EventArgs e)
        {
            SearchContractor();
        }

        protected void DataPager1_OnPreRender(object sender, EventArgs e)
        {
            //ViewContractor();
            SearchContractor();
        }

        protected void FilterLinkButton_OnClick(object sender, EventArgs e)
        {
            SearchContractor();
        }

        protected void DeleteButton_OnCommand(object sender, CommandEventArgs e)
        {
            var contractorEntity = new ContractorEntity { ContractorId = new Guid(e.CommandArgument.ToString()) };
            ContractorBusiness.Delete(contractorEntity);
            SearchContractor();
        }

        protected void ActiveDropDownListSelectedIndexChanged(object sender, EventArgs e)
        {
            SearchContractor();
        }

        protected void ReportButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ReportContractor.aspx");
        }
       
    }
}
